<#escape x as (x)!"">
package ${basePackage}.${plate}.${modulePackage}.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import ${basePackage}.common.excel.Column;
import ${basePackage}.common.excel.ExcelExport;

import ${basePackage}.mgt.sys.controller.AbstractController;
import ${basePackage}.${platPackage}.${modulePackage}.dto.${className}Query;
import ${basePackage}.entity.${modulePackage}.${className}Entity;
import ${basePackage}.${platPackage}.${modulePackage}.service.${className}Service;
import ${basePackage}.utils.Query;
import com.github.pagehelper.Page;
import ${basePackage}.result.Result;
import ${basePackage}.result.ResultGenerator;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * ${comments}
 * 
 * @author ${author}
 * @email ${email}
 * @date ${datetime}
 */
 @SuppressWarnings("rawtypes")
@RestController
@Api("${comments}")
@RequestMapping("${pathName}")
public class ${className}Controller extends AbstractController {
	@Autowired
	private ${className}Service ${classname}Service;
	
	/**
	 * 列表
	 */
	@PostMapping("/list")
	@ApiOperation(value = "列表", notes = "说明")
	@RequiresPermissions("${pathName}:list")
	public Result list(@RequestBody ${className}Query ${classname}Query){

		Map map = ${classname}Query.toSqlMap(this.getProvinceId());

		List<${className}Entity> list = ${classname}Service.queryList(map);

		Page<${className}Entity> page = new Page();

		page.addAll(list);
		page.setPages(1);
		page.setTotal(list.size());
		page.setPageSize(10000);

		return ResultGenerator.successPage(page);
	}
	
	/**
	 * 生成sql
	 */
	@PostMapping("/tosql")
	@ApiOperation(value = "生成sql", notes = "说明")
	@RequiresPermissions("${pathName}:info")
	public Result tosql(@RequestBody ${className}Query ${classname}Query){

		String sql = ${classname}Query.toSqlString(this.getProvinceId());

		return ResultGenerator.successData(sql);
	}


	@RequestMapping("/download")
	@ApiOperation(value = "下载", notes = "说明")
	@RequiresPermissions("${pathName}:list")
	public void download(HttpServletRequest request, HttpServletResponse response) {

		HttpServletRequest orgRequest = XssHttpServletRequestWrapper.getOrgRequest(request);
		String query = orgRequest.getParameter("query");

		${className}Query ${classname}Query = JSON.parseObject(query, ${className}Query.class);

		Map querymap = ${classname}Query.toSqlMap(this.getProvinceId());
		List<${className}Entity> list = ${classname}Service.queryList(querymap);

		if (list != null && list.size() > 0) {
			Map map = new HashMap();

	<#if columns??>
		<#list columns as column>
		<#if column.map??>
            <#if column.attrType="String">
               Map<String, String> ${column.attrname}Map = new HashMap<String, String>();

                <#list column.map?keys as key>
                ${column.attrname}Map.put("${key}", "{column.map[key]}");
                </#list>

            <#else>
               Map<Integer, String> ${column.attrname}Map = new HashMap<Integer, String>();

                <#list column.map?keys as key>
                ${column.attrname}Map.put(${key}, "{column.map[key]}");
                </#list>
            </#if>
            map.put("${column.attrname}Map", ${column.attrname}Map);
		</#if>
		</#list>
	</#if>

			List<Column> clist = new ArrayList();
			Column cloumn = null;

	<#if columns??>
		<#list columns as column>
		    <#if column.map??>
            cloumn = new Column("${column.shortComments}", "${column.attrname}", 2);
			clist.add(cloumn);
			<#else>
            cloumn = new Column("${column.shortComments}", "${column.attrname}", 1);
			clist.add(cloumn);
			</#if>
		</#list>
	</#if>
			try {
				ExcelExport export = exportList(list, clist, map);
				if (export != null) {
					this.downExcel(export, response);
					//this.downzip(export, response);
				}

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}
</#escape>